﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NC.Service.CatchManager;
using NC.Service.MemoryCache;
using NC.Web.Models;

namespace NC.Web.Controllers
{
    public class ApiController : Controller
    {

        private readonly IMemoryCacheService _memoryCacheService;
        private readonly ICatchService _catchService;

        public ApiController(IMemoryCacheService memoryCacheService, ICatchService catchService)
        {
            this._catchService = catchService;
            this._memoryCacheService = memoryCacheService;
        }

        [Route("api/getAccessToken")]
        public JsonResult GetAccessToken(string appId = "")
        {
            if(string.IsNullOrEmpty(appId))
                return new ApiJson("appId为空或格式错误");
            try
            {
                string accessToken = _memoryCacheService.GetAccessTokenByAppId(appId);
                return new ApiJson(accessToken,ResultStatus.Ok);
            }
            catch (Exception e)
            {
                return new ApiJson(e.Message);
            }
        }
        //获取某List下a标签列表
        [Route("api/list/{moduleId}")]
        public JsonResult GetUrlListATags(string accessToken, string moduleId)
        {
            if(string.IsNullOrEmpty(accessToken)||string.IsNullOrEmpty(moduleId))
                return new ApiJson("accessToken和moduleId参数不能为空");
            int module;
            if (!int.TryParse(moduleId, out module))
                return new ApiJson("moduleId参数格式错误");
            var tags=
            return new ApiJson();
        }
        //获取某List下a标签的内容
        [Route("api/list/{moduelId}/p/{url}")]
        public JsonResult GetUrlListAContent(string accessToken, string listId, string url)
        {
            return new ApiJson();
        }

    }
}